package com.smartlifev30.mvp.module;

import android.content.Context;

import com.smartlifev30.baiwei.Config;
import com.smartlifev30.utils.SharedPreferencesUtil;

import smartlifev30.com.sdk.api.CallBack;
import smartlifev30.com.sdk.api.service_app.IUserMgmt;
import smartlifev30.com.sdk.api.service_app.UserMgmtImpl;
import smartlifev30.com.sdk.bean.response.LoginResponse;
import smartlifev30.com.sdk.net.baiwei.NetManager;

/**
 * @author tys
 * @date 2018/8/29
 */

public class PrepareActivityModel implements IPrepareActivityModel {

    @Override
    public int getLastVersionCode(Context context) {
        return SharedPreferencesUtil.getInt(context, SharedPreferencesUtil.VERSION_CODE);
    }

    @Override
    public void setLastVersionCode(Context context, int versionCode) {
        SharedPreferencesUtil.putInt(context, SharedPreferencesUtil.VERSION_CODE, versionCode);
    }


    @Override
    public String getServerToken(Context context) {
        return SharedPreferencesUtil.getString(context, SharedPreferencesUtil.REMOTE_TOKEN);
    }

    @Override
    public String getUserName(Context context) {
        return SharedPreferencesUtil.getString(context, SharedPreferencesUtil.USER_NAME);
    }

    @Override
    public void loginServerByToken(String user, String token, CallBack<LoginResponse> callBack) {
        IUserMgmt userMgmt = new UserMgmtImpl();
        userMgmt.loginByToken(user, token, callBack);
    }

    @Override
    public void saveLoinInfoByToken(String userName, String token) {
        NetManager instance = NetManager.getInstance();
        instance.setUserAndToken(userName, token);

        Config config = Config.getInstance();
        config.setRemoteToken(token);
        config.setUserName(userName);
    }
}
